#!/bin/bash                                                                                                

#SBATCH -c 8
#SBATCH -N 1
#SBATCH -t 3:59:00
#SBATCH -p huce_intel
#SBATCH --constraint=intel
#SBATCH --mem=2500
#SBATCH --mail-type=ALL
#SBATCH --no-requeue
#SBATCH --mail-user=kelvin_bates@g.harvard.edu
#SBATCH -o stdout.%j
#SBATCH -e stdout.%j

ctr=162
sed -i "s/RTOL(i) = 1.0d-4/RTOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90
sed -i "s/ATOL(i) = 1.0d-3/ATOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90

for valAROMmag in 5
do
    for valAROM in 1
    do
        sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2401E-8)#($valAROM.0E-$valAROMmag*1.2401E-8)#g" aromatics_kpp_Rates.f90
        sed -i "s#(..0E-.*1.2023E-8)#($valAROM.0E-$valAROMmag*1.2023E-8)#g" aromatics_kpp_Rates.f90
        sed -i "s#(..0E-.*6.6138E-9)#($valAROM.0E-$valAROMmag*6.6138E-9)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
                sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
            done
        done
    done
done
sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2023E-8)#(0.0E-9*1.2023E-8)#g" aromatics_kpp_Rates.f90
sed -i "s#(..0E-.*6.6138E-9#(0.0E-9*6.6138E-9#g" aromatics_kpp_Rates.f90
ctr=468
for valAROMmag in 5
do
    for valAROM in 5
    do
        sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2401E-8)#($valAROM.0E-$valAROMmag*1.2401E-8)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
                sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
            done
        done
    done
done
sed -i "s#(1.5E-4)\*(..0E-.)#(1.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2401E-8)#(0.0E-9*1.2401E-8)#g" aromatics_kpp_Rates.f90
ctr=720
for valAROMmag in 5 
do
    for valAROM in 2
    do
        sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*1.2023E-8)#($valAROM.0E-$valAROMmag*1.2023E-8)#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
                sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
            done
        done
    done
done
sed -i "s#(0.5E-4)\*(..0E-.)#(0.5E-4)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(..0E-.*1.2023E-8)#(0.0E-9*1.2023E-8)#g" aromatics_kpp_Rates.f90
ctr=990
for valAROMmag in 5
do
    for valAROM in 2
    do
        sed -i "s#(0.7E-5)\*(..0E-.)#(0.7E-5)\*($valAROM.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
        sed -i "s#(..0E-.*6.6138E-9#($valAROM.0E-$valAROMmag*6.6138E-9#g" aromatics_kpp_Rates.f90
        for valNOmag in 9 8 7 6 5 4
        do
            for valNO in 1 2 5
            do
                sed -i "s#(5.0E-3)\*(..0E-.)#(5.0E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                sed -i "s#(..0E-.*2.7558E-7)#($valNO.0E-$valNOmag*2.7558E-7)#g" aromatics_kpp_Rates.f90
                rm *.exe *.o *.mod
                make -f Makefile_aromatics_kpp
                ./aromatics_kpp.exe
                ctr=$[ctr+1]
                mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
                sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_new_ambient_p20_$ctr.dat
            done
        done
    done
done

# Exit normally
exit 0
#EOC
